<%@ page import="cn.bdqn.news.entity.User" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Title</title>
</head>
<body>
<!-- 1.存放数据到四大作用域 set -->
<c:set var="hello" value="<h1>Hello Wolrd!</h1>" scope="session"></c:set>
<!-- 2.显示数据 out 控制默认值和标签是否翻译 -->
<p>${sessionScope.hello}</p>
<p>请求作用域：${requestScope.hello}</p>
<c:out value="${sessionScope.hello}" escapeXml="true"></c:out>
<c:out value="${requestScope.hello}" default="未定义"></c:out>
<!--3.删除 remove-->
<c:remove var="hello" scope="session"></c:remove>
<p>作用域：${hello}</p>
<!-- 4.判断 if-->
<%
    session.setAttribute("user","admin");
%>
<c:if test="${not empty sessionScope.user}"><!-- user不为空 -->
<h1>欢迎</h1>
</c:if>
<c:if test="${empty sessionScope.user}"><!-- user为空 -->
<h1>请登录</h1>
</c:if>
<!-- 5. 分支判断 choose -->
<%
    User user = new User();
    user.setUrole(5);
    session.setAttribute("loginUser",user);
%>
<c:choose>
    <c:when test="${loginUser.urole == 1}">
        <p>注册用户</p>
    </c:when>
    <c:when test="${loginUser.urole == 2}">
        <p>管理员</p>
    </c:when>
    <c:when test="${loginUser.urole == 3}">
        <p>老板</p>
    </c:when>
    <c:otherwise>
        <p>默认值：未知身份，请联系管理员</p>
    </c:otherwise>
</c:choose>
<!-- 6.foreach 循环 -->
<%
    List<String> list = new ArrayList<>();
    for(int i=0;i<10;i++){
        list.add("1000"+i);
    }
    session.setAttribute("nameList",list);

%>
<ul>
    <c:forEach items="${sessionScope.nameList}" var="name">
        <li>${name}</li>
    </c:forEach>
</ul>
<ul>
    <c:forEach items="${sessionScope.nameList}" var="name"
               begin="5" end="8" step="2" varStatus="status">
        <li>${status.index}=${name}</li>
    </c:forEach>
</ul>
<c:set var="appName" value="news" scope="application"></c:set>
<c:remove var="appName" scope="application"></c:remove>
</body>
</html>
